package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.common.core.security.OpenHelper;
import com.flyme.common.core.security.OpenUserAuth;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysOperationlogRemoteService;
import com.flyme.module.base.client.entity.SysCompany;
import com.flyme.module.base.client.entity.SysOperationlog;
import com.flyme.module.base.provider.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工作经历
 *
 * @author zyf
 */
@Api(tags = "操作日志管理")
@RestController
public class SysOperationlogController extends BaseController<SysOperationlogService, SysOperationlog> implements SysOperationlogRemoteService {

    @Autowired
    private SysOperationlogService sysOperationlogService;

    @ApiOperation(value = "添加操作日志", notes = "添加操作日志")
    public ResultBody addOperation(String opremark ) {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        SysOperationlog operationlog = new SysOperationlog();
        operationlog.setUserId(userAuth.getUserId());
        operationlog.setUserName(userAuth.getUsername());
        operationlog.setOpremark(opremark);
        boolean tag = sysOperationlogService.saveOrUpdate(operationlog);
        return ResultBody.success(tag);
    }

    /**
     * 操作日志列表
     */
    @ApiOperation(value = "操作日志列表", notes = "操作日志列表")
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo, @ModelAttribute SysOperationlog operationlog) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*");
        cq.like("opremark", operationlog.getOpremark());
        cq.like("userName", operationlog.getUserName());
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

}
